import { _decorator, Component, Node, math,instantiate,UITransform } from 'cc';
const { ccclass, property } = _decorator;
const {Vec3}  = math

@ccclass('bg')
export class bg extends Component {
     // 移动速度
     public speed: number = 300;
     startPosition = new Vec3()
     onLoad() {
        this.startPosition = instantiate(this.node).position // 克隆
    }
    start() {
        
    }

    update(deltaTime: number) {
     this.run(deltaTime)
    }

    run(deltaTime:number){
        let m = new Vec3(0,-this.speed*deltaTime,0)
        let b = m.add(this.node.position)   
        
        this.node.position = b
        let h = this.startPosition.y - Number(this.node.getComponent(UITransform).height)
    
        if(this.node.position.y < h){
            this.node.position = this.startPosition
        }
    }
    
}


